package com.xk857.article.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xk857.article.req.LabelREQ;
import com.xk857.article.service.ILabelService;
import com.xk857.entities.Label;
import com.xk857.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 星空小屋-知识点表 前端控制器
 *
 * @author CV大魔王
 * @since 2021-02-21
 */
@Api(value = "知识点管理接口", tags = "知识点管理接口")
@RestController
@RequestMapping("/pri/label")
public class LabelController {


    @Autowired
    private ILabelService labelService;

    @ApiOperation("根据知识点名称与模块id查询页面分页列表接口")
    @PostMapping("/search") // post方式请求 /label/search
    public IPage<Label> search(@RequestBody LabelREQ req) {
        return labelService.queryPage(req);
    }


    @ApiOperation("查询知识点详情接口")
    @ApiImplicitParam(name = "id", value = "知识点ID", required = true)
    @GetMapping("/{id}")
    public Label view(@PathVariable String id) {
        return labelService.getById(id);
    }

    @ApiOperation("修改知识点信息接口")
    @PutMapping
    public Result update(@RequestBody Label label) {
        labelService.updateById(label);
        return Result.ok("修改成功");
    }

    @ApiOperation("新增知识点信息接口")
    @PostMapping
    public Result save(@RequestBody Label label) {
        labelService.save(label);
        return Result.ok("添加成功");
    }

    @ApiImplicitParam(name = "id", value = "知识点ID", required = true)
    @ApiOperation("删除知识点接口")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id) {
        labelService.removeById(id);
        return Result.ok("删除成功");
    }
}
